package com.android.djlmapp.activity.my;

import android.net.Uri;
import android.support.constraint.ConstraintLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.android.djlmapp.activity.home.web.base.BaseWebActivity;
import com.android.djlmapp.http.GlobalUrls;
import com.android.djlmapp.token.GetUrlStr;

import butterknife.BindView;

public class AboutUsActivity extends BaseWebActivity {
    @BindView(R.id.ll_top_back)
    LinearLayout llTopBack;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.home_iv_readpoint)
    ImageView homeIvReadpoint;
    @BindView(R.id.iv_top_msg)
    ConstraintLayout ivTopMsg;
    @BindView(R.id.iv_top_set)
    ImageView ivTopSet;
    @BindView(R.id.iv_top_kf)
    ImageView ivTopKf;
    @BindView(R.id.page_title_layout)
    ConstraintLayout pageTitleLayout;

    @Override
    protected void initView() {
        setWebViewClient(mWebViewClient);

        llTopBack.setVisibility(View.VISIBLE);
        ivTopMsg.setVisibility(View.GONE);
        ivTopSet.setVisibility(View.GONE);
        ivTopKf.setVisibility(View.GONE);
        tvName.setText("关于我们");

        String url = GlobalUrls.ABOUOT_US + "?token=" + getToken() + "&version=" + getVersion();
        setWebUrl(url);

        super.initView();
    }


    public WebViewClient mWebViewClient = new WebViewClient() {
        /**
         * 充值功能特有
         * @param view
         * @param request
         * @return
         */
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                Uri uri = request.getUrl();
                String strUrl = uri.getPath();
                // 刷新token
                if (strUrl.contains(TOKEN_DEAD_URL)) {
                    GetUrlStr.getStrUrl(AboutUsActivity.this);
                    return true;
                }
            }
            return super.shouldOverrideUrlLoading(view, request);
        }

        /**
         * 充值功能特有
         * @param view
         * @param url
         * @return
         */
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.i("返利说明", "shouldOverrideUrlLoading: " + url + "  " + TO_FORGET_PSW_URL);
            // 刷新token
            if (url.contains(TOKEN_DEAD_URL)) {
                GetUrlStr.getStrUrl(AboutUsActivity.this);
                return true;
            } else {
                return false;
            }
        }
    };

}
